package cn.analysis.common;

/** 封装统一返回结果类型 */
public class ResultVO {
    private Integer code; // 标识
    private String msg; // 返回消息
    private String remark; // 备注
    private Object data; // 携带数据

    /**  封装请求成功的返回. */
    public static ResultVO success(){
        ResultVO vo = new ResultVO();
        vo.setResultCode(ResultCode.SUCCESS);
        return vo;
    }

    public static ResultVO success(Object data){
        ResultVO vo = new ResultVO();
        vo.setResultCode(ResultCode.SUCCESS);
        vo.setData(data);
        return vo;
    }

    public static ResultVO success(ResultCode code){
        ResultVO vo = new ResultVO();
        vo.setResultCode(code);
        return vo;
    }

    /**  封装请求失败的返回. */
    public static ResultVO failure(){
        ResultVO vo = new ResultVO();
        vo.setResultCode(ResultCode.FAILURE);
        return vo;
    }

    public static ResultVO failure(String msg){
        ResultVO vo = ResultVO.failure();
        vo.setRemark(msg);
        return vo;
    }

    public static ResultVO failure(ResultCode code){
        ResultVO vo = new ResultVO();
        vo.setResultCode(code);
        return vo;
    }

    /**  封装请求出错的返回. */
    public static ResultVO error(){
        ResultVO vo = new ResultVO();
        vo.setResultCode(ResultCode.FAILURE);
        return vo;
    }

    public static ResultVO error(String msg){
        ResultVO vo = ResultVO.failure();
        vo.setMsg(msg);
        return vo;
    }

    public static ResultVO error(Integer code, String msg){
        ResultVO vo = new ResultVO();
        vo.setCode(code);
        vo.setMsg(msg);
        return vo;
    }

    public static ResultVO error(ResultCode code){
        ResultVO vo = new ResultVO();
        vo.setResultCode(code);
        return vo;
    }

    private void setResultCode(ResultCode code){
        this.code = code.getCode();
        this.msg  =code.getMsg();
        this.remark = code.getRemark();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultVO{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", remark ='" + remark + '\'' +
                ", data=" + data +
                '}';
    }
}
